﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.Common.Utilities;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;

namespace JM.JCY.SharePointComponent.PersonalHome.PublicUser
{
    public partial class PublicUserUserControl : UserControl
    {
        public int _userId
        {
            set { ViewState["_userId"] = value; }
            get { return (int)ViewState["_userId"]; }
        }

        public string _userName
        {
            set { ViewState["_userName"] = value; }
            get { return (string)ViewState["_userName"]; }
        }

        public int _staffId
        {
            set { ViewState["_staffId"] = value; }
            get { return (int)ViewState["_staffId"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ApplicationContext.Current.GetKeyValue("userId") != null)
            {
                _userId = Int32.Parse(ApplicationContext.Current.GetKeyValue("userId").ToString());
            }
            if (ApplicationContext.Current.UserName != null)
            {
                _userName = ApplicationContext.Current.UserName.ToString();
            }

            if (!IsPostBack)
            {
                if (Request.QueryString["StaffId"] != null)
                {
                    this.hfStaffd.Value = Request.QueryString["StaffId"].ToString();
                    _staffId = Int32.Parse(Request.QueryString["StaffId"].ToString());
                    LoadUserInfo();

                }

            }
        }

        private void LoadUserInfo()
        {
            using (UserManagementProxy proxy = new UserManagementProxy())
            {
                var dt = proxy.GetUserForHome(_staffId);
                var userRow = dt[0];
                var dtCulture = proxy.GetUser(_staffId, string.Empty);

                this.lblNameDis.Text = userRow.UserName;
                this.lblDeptDis.Text = userRow.DeptName;
                this.imgUserPhotoDis.ImageUrl = userRow.PhotoImagePath;

                this.lblOffice.Text = userRow.OfficeAddress;
                this.lblOfficeNumber.Text = userRow.OfficeNumber;
                this.lblHomeNumber.Text = userRow.HomeNumber;
                this.lblMobileNumber.Text = userRow.MobileNumber;
                this.lblEmail.Text = userRow.Email;
                this.lblUserCulture.Text = dtCulture[0].Culture;
                this.TRImage.Visible = false;
            }
        }


    }
}
